<?php

/**
 * Application Models
 *
 * @package Application_Model
 * @subpackage Model
 * @author <YOUR NAME HERE>
 * @copyright ZF model generator
 * @license http://framework.zend.com/license/new-bsd     New BSD License
 */

/**
 * Abstract class for models
 */
require_once 'ModelAbstract.php';

/**
 * AUTOLOAD,AUTOLOADPLAN,MANUALLOAD
 *
 * @package Application_Model
 * @subpackage Model
 * @author <YOUR NAME HERE>
 */
class Application_Model_RolePersonne extends Application_Model_ModelAbstract
{

    /**
     * Database var type int(11)
     *
     * @var int
     */
    protected $_Idrolepersonne;

    /**
     * Database var type int(11)
     *
     * @var int
     */
    protected $_PersonnesIdpersonnes;

    /**
     * Database var type varchar(255)
     *
     * @var string
     */
    protected $_RoleIdrole;


    /**
     * Parent relation fk_role_personne_personnes1
     *
     * @var Application_Model_Personnes
     */
    protected $_Personnes;

    /**
     * Parent relation fk_role_personne_role1
     *
     * @var Application_Model_Role
     */
    protected $_Role;


    /**
     * Dependent relation fk_PILOT_PROJET_ROL_role_personne1
     * Type: One-to-Many relationship
     *
     * @var Application_Model_PilotProjetRol
     */
    protected $_PilotProjetRol;

    /**
     * Sets up column and relationship lists
     */
    public function __construct()
    {
        parent::init();
        $this->setColumnsList(array(
            'idrolepersonne'=>'Idrolepersonne',
            'personnes_idpersonnes'=>'PersonnesIdpersonnes',
            'role_idrole'=>'RoleIdrole',
        ));

        $this->setParentList(array(
            'FkRolePersonnePersonnes1'=> array(
                    'property' => 'Personnes',
                    'table_name' => 'Personnes',
                ),
            'FkRolePersonneRole1'=> array(
                    'property' => 'Role',
                    'table_name' => 'Role',
                ),
        ));

        $this->setDependentList(array(
            'FkPILOTPROJETROLRolePersonne1' => array(
                    'property' => 'PilotProjetRol',
                    'table_name' => 'PilotProjetRol',
                ),
        ));
    }

    /**
     * Sets column idrolepersonne
     *
     * @param int $data
     * @return Application_Model_RolePersonne
     */
    public function setIdrolepersonne($data)
    {
        $this->_Idrolepersonne = $data;
        return $this;
    }

    /**
     * Gets column idrolepersonne
     *
     * @return int
     */
    public function getIdrolepersonne()
    {
        return $this->_Idrolepersonne;
    }

    /**
     * Sets column personnes_idpersonnes
     *
     * @param int $data
     * @return Application_Model_RolePersonne
     */
    public function setPersonnesIdpersonnes($data)
    {
        $this->_PersonnesIdpersonnes = $data;
        return $this;
    }

    /**
     * Gets column personnes_idpersonnes
     *
     * @return int
     */
    public function getPersonnesIdpersonnes()
    {
        return $this->_PersonnesIdpersonnes;
    }

    /**
     * Sets column role_idrole
     *
     * @param string $data
     * @return Application_Model_RolePersonne
     */
    public function setRoleIdrole($data)
    {
        $this->_RoleIdrole = $data;
        return $this;
    }

    /**
     * Gets column role_idrole
     *
     * @return string
     */
    public function getRoleIdrole()
    {
        return $this->_RoleIdrole;
    }

    /**
     * Sets parent relation PersonnesIdpersonnes
     *
     * @param Application_Model_Personnes $data
     * @return Application_Model_RolePersonne
     */
    public function setPersonnes(Application_Model_Personnes $data)
    {
        $this->_Personnes = $data;

        $primary_key = $data->getPrimaryKey();
        if (is_array($primary_key)) {
            $primary_key = $primary_key['idpersonnes'];
        }

        $this->setPersonnesIdpersonnes($primary_key);

        return $this;
    }

    /**
     * Gets parent PersonnesIdpersonnes
     *
     * @param boolean $load Load the object if it is not already
     * @return Application_Model_Personnes
     */
    public function getPersonnes($load = true)
    {
        if ($this->_Personnes === null && $load) {
            $this->getMapper()->loadRelated('FkRolePersonnePersonnes1', $this);
        }

        return $this->_Personnes;
    }

    /**
     * Sets parent relation RoleIdrole
     *
     * @param Application_Model_Role $data
     * @return Application_Model_RolePersonne
     */
    public function setRole(Application_Model_Role $data)
    {
        $this->_Role = $data;

        $primary_key = $data->getPrimaryKey();
        if (is_array($primary_key)) {
            $primary_key = $primary_key['idrole'];
        }

        $this->setRoleIdrole($primary_key);

        return $this;
    }

    /**
     * Gets parent RoleIdrole
     *
     * @param boolean $load Load the object if it is not already
     * @return Application_Model_Role
     */
    public function getRole($load = true)
    {
        if ($this->_Role === null && $load) {
            $this->getMapper()->loadRelated('FkRolePersonneRole1', $this);
        }

        return $this->_Role;
    }

    /**
     * Sets dependent relations fk_PILOT_PROJET_ROL_role_personne1
     *
     * @param array $data An array of Application_Model_PilotProjetRol
     * @return Application_Model_RolePersonne
     */
    public function setPilotProjetRol(array $data)
    {
        $this->_PilotProjetRol = array();

        foreach ($data as $object) {
            $this->addPilotProjetRol($object);
        }

        return $this;
    }

    /**
     * Sets dependent relations fk_PILOT_PROJET_ROL_role_personne1
     *
     * @param Application_Model_PilotProjetRol $data
     * @return Application_Model_RolePersonne
     */
    public function addPilotProjetRol(Application_Model_PilotProjetRol $data)
    {
        $this->_PilotProjetRol[] = $data;
        return $this;
    }

    /**
     * Gets dependent fk_PILOT_PROJET_ROL_role_personne1
     *
     * @param boolean $load Load the object if it is not already
     * @return array The array of Application_Model_PilotProjetRol
     */
    public function getPilotProjetRol($load = true)
    {
        if ($this->_PilotProjetRol === null && $load) {
            $this->getMapper()->loadRelated('FkPILOTPROJETROLRolePersonne1', $this);
        }

        return $this->_PilotProjetRol;
    }

    /**
     * Returns the mapper class for this model
     *
     * @return Application_Model_Mapper_RolePersonne
     */
    public function getMapper()
    {
        if ($this->_mapper === null) {
            $this->setMapper(new Application_Model_Mapper_RolePersonne());
        }

        return $this->_mapper;
    }

    /**
     * Deletes current row by deleting the row that matches the primary key
     *
	 * @see Application_Model_Mapper_RolePersonne::delete
     * @return int|boolean Number of rows deleted or boolean if doing soft delete
     */
    public function deleteRowByPrimaryKey()
    {
        if ($this->getIdrolepersonne() === null) {
            throw new Exception('Primary Key does not contain a value');
        }

        return $this->getMapper()
                    ->getDbTable()
                    ->delete('idrolepersonne = ' .
                             $this->getMapper()
                                  ->getDbTable()
                                  ->getAdapter()
                                  ->quote($this->getIdrolepersonne()));
    }
}
